

# Please install OpenAI SDK first: `pip3 install openai`


from DeepSeekAPI import *
import time,json
from config import *
import pandas as pd


t0 = time.time()

# 调用测试
t = TestAPI(api_key, base_url)


# r"E:\项目文件\DeepSeek研究\测试对比文案挑选数据\res_result.xlsx"
# r"C:\Users\Administrator\Desktop\测试---DeepSeek文案\select_line_product_res_result.xlsx"  2025-02-14 17:20:21

desc_path = "/mnt/c/Users/Administrator/Desktop/测试---DeepSeek文案/select_line_product_res_result.xlsx"
df = pd.read_excel(desc_path)



def get_sku_info(sku):
	
	df_x = df[df['sku']==sku]

	sku = df_x.values[0][0]
	title = df_x.values[0][1]
	info_product = df_x.values[0][9]


	ask_text = f'''
	Please understand this set of Amazon title copywriting model: core keywords, brand name + feature selling point + secondary keywords + secondary keywords + (with) + for applicable scope.
 
	Now you are an Amazon operator with more than 5 years of experience in Amazon operations.
	You need to: refer to the title structure style of similar Amazon big sellers, and the characteristics that a good Amazon title should have. Follow the steps below to complete the writing of an Amazon title with 160-180 characters in English.
	
	Step 1:
	1. Read the titles of the following 5 competing links to help extract the product features and product keywords in English, respectively.
	Note that:
	1. the product features are presented in a concise English phrase.
	2. product keywords are near-synonymous expressions or long-tail words for that product.
	{{
		"my_title": "{ title }"
		
	}}
	
	Step 2:
	My product information is as follows:
	{info_product}

	Refer to the characteristics and keywords of the big_sale_tiltes competing links in step 1.
	Prioritize the use of keywords and selling points that match my product and put them in my product title.
	The headline needs to meet both the following requirements:
	1. the features need to be presented in a concise English phrase.
	2. the keyword is a synonymous expression or long-tail word for the product.
	3. the title should contain 3 keywords about the product itself. 4.
	4. the keywords and selling points need to be ordered to meet the requirement that the more frequent ones appear in front of the title.
	5. All content expressions in the title must come from my own product's copy itself and from the referenced competing products.
	Please write the Amazon title of my product.
	

	Step Three:
	Revise the title written in step 2.
	Make the changes according to the following requirements:
	1. add a comma after the first keyword of the product.
	2. and meet the following ordering requirements:
	The content of the with structure, and the content of the for structure need to be at the end of the title. Also, the content of the with structure should precede the content of the for structure and be separated by commas. 
	3. Please reduce the total number of characters in the title to less than 180 characters. 
	4. Only one with can appear in the title. 
	5. Only one 1 for can appear in the title.
	6. Write in English.
	7. the title should be easy to understand and ensure readability.
	8. conform to the title style of the Amazon platform. 
	9. Any numbers in the title should use Arabic numerals rather than words. 
	10. try to avoid the use of special characters in the title. If necessary, use English commas to separate them. 
	11. Do not include any other brand names or infringing information in the title. The brand of the product. 
	12. Do not include any promotional information in the title, for example, do not use: high qualiy, sale, promotion, durable, ideal , Excellent such terms.
	13. the title should contain the important features of the product, selling points.
	
	Step 4, please write my Amazon title.
	Please follow the following steps to make changes to the title:
	Step 1:
	Add a comma after the first keyword of the product.
	Step 2:
	Use only one with in the whole title, delete the extra with in the title.
	Step 3:
	Use only one for in the whole title, delete the redundant for in the title. 
	Step 4:
	Delete the promotional words in the title, for example, do not use: high qualiy, sale, promotion, durable, Ideal, such words.
	Step 5.
	Replace any numbers that appear in the headline with Arabic numerals instead of words.
	Step 6.
	The title should contain 3 keywords about the product itself.
	Step 7.
	Remove any special characters from the title. If necessary, use English commas to separate them. 
	Step 8.
	Please limit the number of characters in the title: English text to 160-180 characters.
	Step nine.
	Give the title directly without quotation marks, periods, and other symbols. 
	Step 10.
	Delete redundant descriptors, modifiers, etc. from the title.
	Finally, please output the finished title .

	最后输出只输出标题 格式为 {{"title": "400W Switching Power Supply Indoor LED Strip Light Box Driver Power Supply 185‑264VAC Input"}}
	如果提问重复需要保证每次输出的标题不一样'''


	messages= [
    {"role": "system", "content": "你是一位资深的Amazon美国站销售经理;有着丰富的产品撰写刊登以及营销能力;只用给你一些产品的基本信息；你就可以将信息打磨成高质量的产品标题用于Amazon刊登"},
    {"role": "user", "content": ask_text}
	]
	#调用测试--test_api1 输入提问语句
	try:
		# res = ""
		# print(messages)
		res = t.test_api1(messages=messages) # 测试直接聊天
	except:
		res = "Sorry, I cannot understand your question."

	return sku,title, info_product,res
      



from sqlalchemy import create_engine




for sku in set(df['sku']):
	print(sku)
	sku,title, info_product,res= get_sku_info(sku)
	df_res = pd.DataFrame({'sku':[sku], 'erp_title':[title], 'erp_desc':[info_product], 'DeepSeek_title':[res],'write_time':[time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())]})
	# df_res.to_sql('deep_seek_ai_res', con25, if_exists='append', index=False)




# """
# 参考官方文档网址：https://api-docs.deepseek.com/zh-cn/prompt-library/
# ** system: 提示词 给一个定义告诉他是谁 要干啥 指定一个方向
# ** user: 开始提问，输入你的问题以及想到得到的答案要求
# """




# messages= [
#     {"role": "system", "content": "你是一名优秀的数学家"},
#     {"role": "user", "content": "鸡兔共有头50个，腿180个，求鸡和兔的数量？"}
    
# ]



t1 = time.time()
print("Time used:", t1-t0)